import axios from '@/services'
import Page from './Page'
import BaseEntity from './BaseEntity'

class Base extends BaseEntity {
  constructor ({
    id = ''
  }) {
    super({id})
  }
  // 保存
  async save () {
    let res = await Base.$http.post(`${Object.getPrototypeOf(this).constructor.$name}/save`, this)
    return res
  }
  // 删除
  static async remove (params) {
    let res = await Base.$http.get(`${this.$name}/delete/${params.id}`, {params})
    return res
  }
  // 获取列表
  static async find (params) {
    let {content, ...pagination} = await Base.$http.get(`${this.$name}/list`, {params})
    content = content.map(v => new this(v))
    pagination = new Page(pagination)
    return {content, pagination}
  }
  // 获取匹配某id的个体
  static async findOne (params) {
    let res = await Base.$http.get(`${this.$name}/get/${params.id}`, {params})
    return new this(res)
  }
}
// 静态属性
Base.$http = axios
Base.$name = '/base'
export default Base
